<DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>index</title>
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="javascript/vue-element-ui/index.css">
  <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">
  <script src="javascript/vue-element-ui/vue.min.js"></script>
  <script src="javascript/vue-element-ui/index.js"></script>
  <script src="javascript/vue-element-ui/axios.min.js"></script>

</head>
<body>
	<div class="section" id="app" style="background: url('images/login_bg1.jpg'); text-align: center; ">
        <div class="logo_center">
            <div class="center_left">
                <img src="images/qx_logo.png">
                <span>{{title}}</span>
            </div>
            <el-form class="center_right" :model="user" :rules="rules" ref="ruleForm">
                <img class="right_title" src="images/logo_name.png">
                <el-form-item prop="username">
                    <el-input v-model="user.username" prefix-icon="fa fa-user"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input v-model="user.password" prefix-icon="fa fa-unlock-alt"></el-input>
                </el-form-item>
                <el-form-item class="right_jz">
                    <el-button type="primary" @click="onSubmit()">登录</el-button>
                    <el-button type="warning" @click="onRuleform()">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="logo_bottom">
            <span>重庆天气在线科技有限公司  技术支持</span><p>贵州省气象局   版权所有     Copyright@2018 HaiNan Meteorological Bureau</p>
        </div>
	</div>
</body>

<script type="text/javascript">
    var app = new Vue({
        el:'#app',
        data: {
            title:'天气在线项目接口监控系统',
            user:{
                username:'admin',
                password:'123456'
            },
            rules:{
                username:[{
                    required: true, message: '请输入活动名称', trigger: 'blur' ,
                },{
                    min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' ,
                }],
                password:[{
                    required: true, message: '请输入密码', trigger: 'blur' ,
                },{
                    min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' ,
                }]
            },
        },
        methods:{
            //登录
            onSubmit:function(){
                this.$refs.ruleForm.validate((validate)=> {
                    if(!validate) return
                    axios.post('http://127.0.0.1:8888/api/private/v1/login',this.user)
                        .then(res=>{
                            if(res.data.status = 200) 
                            this.$message.success(res.data.meta.msg)
                            window.sessionStorage.setItem('token', res.data.data.token)
                            window.sessionStorage.setItem('usersid', res.data.data.id)
                            window.location.href="home.html"
                        })
                        .catch(error=>{
                            this.$message.error(error)
                        })
                });
            },

            //重置校验
            onRuleform:function(){
                this.$refs.ruleForm.resetFields()
            }
        }
    })
</script>
</html>
